package com.study2.demoShuangLieJiHe;

import java.util.TreeMap;
import java.util.TreeSet;

public class A04_TreeMap {
    /*
     * 同TreeSet 底层原理一致 都是红黑树结构。
     *
     * */
    
    public static void main(String[] args) {
        /*
         * 需求1
         *       键：整数表示id
         *       值：字符串表示商品名称
         *       需求：按照id的升序排列、按照id的降序排列
         * */
        // TreeMap<Integer,String> shopmap = new TreeMap<>((o1,o2)-> o2 -o1);
        // shopmap.put(1,"手机");
        // shopmap.put(2,"电脑");
        // shopmap.put(3,"鼠标");
        // System.out.println(shopmap);
        
        C04_Student s1 = new C04_Student("zhangsan", 23);
        C04_Student s2 = new C04_Student("lisi", 24);
        C04_Student s3 = new C04_Student("wangwu", 25);
        C04_Student s4 = new C04_Student("zhangsan", 23);
        C04_Student s5 = new C04_Student("awei", 23);
        TreeMap<C04_Student, String> map = new TreeMap<>();
        map.put(s1, "上海");
        map.put(s2, "北京");
        map.put(s3, "天津");
        map.put(s4, "深圳");
        map.put(s5, "上海");
        
        map.forEach((k, v) -> System.out.println(k + "--->" + v));
    }
}
